﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Fitment.Admin
{
    public partial class logon : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Cookies["UserName"] != null) // 从客户端读取cookie值
                {
                    Response.Redirect("userMng.aspx");
                }
            }

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string strAccount = this.Login1.UserName.ToString();  //获取账号
            string strPassword = this.Login1.Password.Trim();   //获取密码
            if (this.Login1.RememberMeSet== true)
            {
                Response.Cookies["UserName"].Value = strAccount;  //将值写入到客户端硬盘Cookie
                Response.Cookies["UserName"].Expires = DateTime.Now.AddMinutes(10);//设置Cookie过期时间
            }

            string strSql = "SELECT * FROM Info WHERE RollerID='1' AND Account='"+strAccount+
                "' AND Password='"+strPassword+"'";      //查询用户语句
            DS data = new DS(); //新建数据库连接
            DataTable table=data.GetDataSource(strSql,"Query");    //返回查询结果
            if (table.Rows.Count==0)
            {
                //当查询管理员不存在时返回
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "提示", "<script>alert('管理员不存在，请检查！');</script>");
                return;
            }
            //保存登录的用户名
            Session["LoginUser"] = this.Login1.UserName.ToString();    //这里就是给session赋值了.我对登录用户进行了一些安全处理
            //转到管理首页
            Response.Redirect("userMng.aspx");  //重定向到用户页面
        }
    }
}
